package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * @author Gallant
 * @create 2020-07-12 15:05
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    // 获取运营数据统计数据
    public Map<String, Object> getBusinessReportData() throws Exception {
        Map<String,Object> map = new HashMap<>();
        // 获取当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        map.put("reportDate",today);

        // 获取当前日期的周一
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        // 获取当前日期的1号
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        // 获取todayNewMember
        Integer todayNewMember = memberDao.findNewMemberByToday(today);
        map.put("todayNewMember",todayNewMember);
        // 获取 totalMember
        Integer totalMember = memberDao.findTotalMember();
        map.put("totalMember",totalMember);
        // 获取thisWeekNewMember
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        map.put("thisWeekNewMember",thisWeekNewMember);
        // 获取thisMonthNewMember
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        map.put("thisMonthNewMember",thisMonthNewMember);
        // 获取todayOrderNumber
        Integer todayOrderNumber = orderDao.findTodayOrderNumber(today);
        map.put("todayOrderNumber",todayOrderNumber);
        // 获取todayVisitsNumber
        Integer todayVisitsNumber = orderDao.findTodayVisitsNumber(today);
        map.put("todayVisitsNumber",todayVisitsNumber);
        // 获取thisWeekOrderNumber
        Integer thisWeekOrderNumber = orderDao.findThisWeekOrderNumber(thisWeekMonday);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        // 获取thisWeekVisitsNumber
        Integer thisWeekVisitsNumber = orderDao.findThisWeekVisitsNumber(thisWeekMonday);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        // 获取thisMonthOrderNumber
        Integer thisMonthOrderNumber = orderDao.findThisMonthOrderNumber(firstDay4ThisMonth);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        // 获取thisMonthVisitsNumber
        Integer thisMonthVisitsNumber = orderDao.findThisMonthVisitsNumber(firstDay4ThisMonth);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        // 获取热门数据
        List<Map<String,Object>> hotSetmeal = orderDao.findHotSetmeal();
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }
}
